/*
 * DexOptimize.h
 *
 *  Created on: 2011-7-9
 *      Author: gexiao
 */
/*
 * DEX optimization declarations.
 */
#ifndef DEXOPTIMIZE_H_
#define DEXOPTIMIZE_H_
#include "../Common.h"

#include <stdbool.h>

/*
 * Global DEX optimizer control. Determines the circumstances in which we
 * try to rewrite instructions in the DEX file.
 */
typedef enum DexOptimizerMode {
	OPTIMIZE_MODE_UNKNOWN = 0, OPTIMIZE_MODE_NONE, //never optimize
	OPTIMIZE_MODE_VERIFIED, //only optimize verified classes (default)
	OPTIMIZE_MODE_ALL
//optimize all classes
} DexOptimizerMode;

/*
 * Given the full path to a DEX or Jar file,and (if appropriate) the name
 * within the Jar, open the optimized version from the cache.
 *
 * If "*pNewFile" is set, a new file has been created with only a stub
 * "opt" header, and the caller is expected to fill in the blanks.
 *
 * Returns the file descriptor, lock and seeked past the "opt" header.
 */
int dvmOpenCachedDexFile(const char* fileName, const char* subFileName,
		u4 modWhen, u4 crc, bool isBootstrap, char** pCachedName,
		bool* pNewFile, bool createIfMissing);

/*
 * Unlock the specified file descriptor. Use in conjunction with
 * dvmOpenCachedDexFile().
 *
 * Returns true on success.
 */bool dvmUnlockCachedDexFile(int fd);

/*
 * Verify the contents of the "opt" header, and check the DEX file's
 * dependencies on its source zip (if available).
 */bool dvmCheckOptHeaderAndDependencies(int fd, bool sourceAvail, u4 modWhen,
		u4 crc, bool expectVerify, bool expectOpt);

/*
 * Optimize a DEX file. The file must start with the "opt" header, followed
 * by the plain DEX data. It must be mmap()able.
 *
 * "fileName" is only used for debug output.
 */bool dvmOptimizeDexFile(int fd, off_t dexOffset, long dexLen,
		const char* fileName, u4 modWhen, u4 crc, bool isBootstrap);
#endif /* DEXOPTIMIZE_H_ */
